const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    page:1,
    pageSize:10,
    isEnd:false,
    lists:[],
    type:1
  },
  onLoad: function (options) {
    this.myHealthReportList()
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },
  tabs(e){
    this.setData({
      page:1,
      pageSize:10,
      isEnd:false,
      lists:[],
      type:e.currentTarget.dataset.type
    })
    this.myHealthReportList()
  },
  golink(e){
    if (!wx.getStorageSync('logintoken')) {
      app.ToLogin(true)
      return
    }
    var url=e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    })
  },
  myHealthReportList(){
    Controller.myHealthReportList({memberType:this.data.type,page:this.data.page,pageSize:this.data.pageSize}).then(res=>{
      if(res.data.baseData && res.data.baseData.list.length>0){
        this.setData({
          lists:this.data.lists.concat(res.data.baseData.list),
        })
      }
      if(res.data.baseData.lastPage){
        this.setData({
          isEnd:res.data.baseData.lastPage
        })
      }
    })
  },
  onReachBottom(){
    if(this.data.isEnd){
      return
    }else{
      this.setData({
        page:this.data.page+1
      })
      this.myHealthReportList()
    }
    
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})